﻿@model PrivateMessageListModel 
@using SmartStore.Web;
@using SmartStore.Web.Extensions;
@using SmartStore.Web.Models.PrivateMessages;
@using SmartStore.Web.Framework.UI;
<div class="private-messages-box">
    <script type="text/javascript">
        $(document).ready(function () {

            $('#select-all-inbox').click(function () {
                $('#pm-inbox-table .rowcheckbox').attr('checked', $(this).is(':checked')).change();
            });

            $('#pm-inbox-table .rowcheckbox').live('change', function (e) {
                var numChkBoxes = $('#pm-inbox-table .rowcheckbox').length;
                var numChkBoxesChecked = $('#pm-inbox-table .rowcheckbox:checked').length;
                $('#select-all-inbox').attr('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
            });
        });
    </script>
    @if (Model.Messages.Count > 0)
    {
        using (Html.BeginRouteForm("PrivateMessagesInbox", FormMethod.Post))
        {
        <table class="table" cellspacing="0" cellpadding="4" id="pm-inbox-table">
            <col width="5%" />
            <col width="20%" />
            <col width="50%" />
            <col width="25%" />
            <thead>
                <tr class="pm-grid-header-style">
                    <th class="a-center">
                        <input type="checkbox" id="select-all-inbox" />
                    </th>
                    <th class="a-center">
                        @T("PrivateMessages.Inbox.FromColumn")
                    </th>
                    <th class="a-center">
                        @T("PrivateMessages.Inbox.SubjectColumn")
                    </th>
                    <th class="a-center">
                        @T("PrivateMessages.Inbox.DateColumn")
                    </th>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < Model.Messages.Count; i++)
                {
                    var item = Model.Messages[i];
                    @*<tr @(i % 2 == 0 ? Html.Raw(" class=\"pm-grid-row-style\"") : Html.Raw(" class=\"pm-grid-alt-row-style\""))>*@
                    <tr class="@((item.IsRead) ? "pm-read" : "pm-unread")">
                        <td class="a-center">
                            <input type="checkbox" name="pm@(item.Id)" class="rowcheckbox" />
                        </td>
                        <td class="a-left">
                            @if (item.AllowViewingFromProfile)
                            {
                                @Html.RouteLink(item.CustomerFromName, "CustomerProfile", new { Id = item.FromCustomerId })
                            }
                            else
                            {
                                @item.CustomerFromName
                            }
                        </td>
                        <td class="a-left">
                            @Html.RouteLink(item.Subject, "ViewPM", new { privateMessageId = item.Id }, new { @class = (item.IsRead) ? "pm-read" : "pm-unread" })
                        </td>
                        <td class="a-left">
                            @item.CreatedOn
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        if (Model.TotalPages > 1)
        {
            @Html.SmartStore().Pager(Model).Name("paginator").Route("PrivateMessagesPaged", ViewData["PagerRouteValues"])
        }
        <div class="buttons">
            <button class="btn btn-danger" name="delete-inbox" value="delete-inbox" type="submit" >
                <i class="icon icon-trash"></i>&nbsp;&nbsp;
                @T("PrivateMessages.Inbox.DeleteSelected")
            </button>

            <button class="btn" name="mark-unread" value="mark-unread" type="submit">
                @T("PrivateMessages.Inbox.MarkAsUnread")
            </button>
        </div>
        }
    }
</div>
